package games.ninJumpDx.ui.actions
{
	import flash.display.Sprite;
	import flash.utils.getTimer;
	
	import games.ninJumpDx.data.GameData;
	import games.ninJumpDx.data.UIConfig;
	import utils.ActionFactory;
	import games.ninJumpDx.ui.factorys.MunitFactory;
	
	import utils.Cartoon;
	
	public class Enemy extends Cartoon
	{
		protected var m_actionFactory:ActionFactory;
		protected var m_action:MoveUnit;
		protected var initY:Number;
		protected var info:XMLList
		
		public function Enemy(name:String)
		{
			super();
			m_actionFactory = new MunitFactory();
			m_action = MoveUnit(m_actionFactory.makeAction(name));
			addChild(m_action);
			info = UIConfig.getInfoByName(name);
			x = info.@x;
			
			y = UIConfig.getInfoByName(name).@y;
			if(info.hasOwnProperty("@scaleX"))
			{
				scaleX = -1;
			}
		}
		
		override public function update(t:Object=null):void
		{
			if(!start || pause)return;
			if(y > UIConfig.getGameHeight())
			{
				destroy();
				return ;
			}
			//var time:Number = getTimer() - m_startTime;
			//y = (time * GameData.instance.speed + initY) ;
			y += GameData.instance.speed ;
		}
		
		override public function destroy(e:* = null):void
		{
			super.destroy();
			removeChild(m_action)
			m_action.destroy();
			m_action = null;
			info = null;
			m_actionFactory = null;
		
		}
	}
}